package cn.wolfcode.business.controller;


import cn.wolfcode.business.domain.BusStatementItem;
import cn.wolfcode.business.domain.StatementItemVO;
import cn.wolfcode.business.service.BusStatementItemService;
import cn.wolfcode.business.service.BusStatementService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/statementitem")
public class BusStatementItemController extends BaseController {
    @Autowired
    BusStatementItemService busStatementItemService;
    /**
     * 保存方法前端传递一个参数 data
     * 传递一个 结算单id和折扣金额给  结算单 BusStatementService 执行update方法
     * 在插入一条数据到 结算单明细表
     *
     */
    @PostMapping
    public AjaxResult save(@RequestBody StatementItemVO statementItemVO){
        return AjaxResult.success(busStatementItemService.save(statementItemVO));
    }
    /**
     * 根据结算id查询结算单明细中所有的结算单信息，返回一个结算单明细列表
     */
    @GetMapping("/{id}")
    public AjaxResult getStatementItem(@PathVariable Long id){
        List<BusStatementItem> statementItem = busStatementItemService.getStatementItem(id);
        System.out.println("statementItem = " + statementItem);
        return AjaxResult.success(statementItem);
    }
    /**
     * 完成支付功能，支付的本质上就是将结算单的状态修改为已支付
     */
    @PatchMapping("/{statementId}")
    public AjaxResult payUpdateStates(@PathVariable Long statementId){
        return  AjaxResult.success(busStatementItemService.payUpdateStates(statementId));
    }
}
